<template>
  <div class="show">
    <div class="imgbox">
      <span @click="back"><i class="el-icon-arrow-left"></i></span>
      <div class="img">
        <img :src="info.i.image" alt="" />
      </div>
      <div class="textbox">
        <div class="name">{{ info.i.name }}</div>
        <div class="sell">
          月售{{ info.i.sellCount }} 好评率{{ info.i.rating }}%
        </div>
        <div class="price">
          <span>￥{{ info.i.price }}</span>
          <span @click="add(info)" v-show="!isAdd">加入购物车</span>
          <span v-show="isAdd" class="added">已加入购物车</span>
        </div>
      </div>
    </div>
    <el-collapse class="introduce" @change="handleChange">
      <el-collapse-item title="商品介绍">
        <div>
          {{ info.i.info }}
        </div>
      </el-collapse-item>
    </el-collapse>
    <CommentsLists :ratings="info.i.ratings"></CommentsLists>
    <Footer></Footer>
  </div>
</template>

<script>
import CommentsLists from "../components/CommentsLists.vue";
import Footer from "../components/Footer.vue";
export default {
  name: "Show",
  data() {
    return {
    };
  },
  components: { Footer, CommentsLists },
  props: ["info"],
  computed:{
    isAdd(){
      return this.info.i.num
    }
  },
  methods: {
    back() {
      this.$router.back();
    },
    add(info) {
      const {i,index,ind} = info;
      this.$store.commit("getDataAbout/addOne", { index, ind });
      this.$store.commit("priceAbout/addCart", { index, ind, i });
    },
    handleChange(val) {
    },
  }
};
</script>

<style scoped>
.show {
  background: #eee;
  padding-bottom: 40px;
}
.imgbox {
  background: #fff;
  height: 340px;
  background: rgb(255, 255, 255);
  position: relative;
  margin-bottom: 20px;
}
.imgbox span {
  position: absolute;
}
.imgbox span:nth-child(1) {
  left: 5px;
  top: 5px;
  color: #fff;
  font-size: 20px;
}
.img {
  width: 100%;
  height: 240px;
}
.img img {
  width: 100%;
  height: 100%;
}
.textbox {
  padding: 15px;
}
.textbox .name {
  font-weight: 600;
}
.textbox .sell {
  font-size: 12px;
  color: #aaa;
}
.imgbox .price span:nth-child(1),
.imgbox .price span:nth-child(2) {
  position: absolute;
  top: 300px;
}
.imgbox .price span:nth-child(1) {
  left: 20px;
  color: red;
  font-size: 14px;
  font-weight: 600;
}
.imgbox .price span:nth-child(2),
.imgbox .price span:nth-child(3) {
  display: block;
  padding: 2px 5px;
  font-size: 10px;
  right: 20px;
  background: rgb(52, 160, 223);
  border-radius: 20px;
  color: #fff;
}

.introduce {
  background: #fff;
  padding: 10px;
  margin-bottom: 20px;
}

.comment {
  height: 200px;
  background: rgb(255, 255, 255);
}
.imgbox .price span:nth-child(3) {
  background: rgba(2, 3, 3, 0.5);
  /* margin-top: 5px; */
}
</style>